/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.common.util.Pair;
/*    */ import com.zimbra.cs.mailbox.Folder;
/*    */ import com.zimbra.cs.mailbox.MailItem;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.Mountpoint;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetItem
/*    */   extends MailDocumentHandler
/*    */ {
/* 37 */   private static final String[] TARGET_ITEM_PATH = { "item", "id" };
/* 38 */   private static final String[] TARGET_FOLDER_PATH = { "item", "l" };
/* 39 */   private static final String[] RESPONSE_ITEM_PATH = new String[0];
/*    */   
/* 41 */   protected String[] getProxiedIdPath(Element request) { if (getXPath(request, TARGET_ITEM_PATH) != null) return TARGET_ITEM_PATH;
/* 42 */     if (getXPath(request, TARGET_FOLDER_PATH) != null) return TARGET_FOLDER_PATH;
/* 43 */     return null; }
/*    */   
/* 45 */   protected boolean checkMountpointProxy(Element request) { return getXPath(request, TARGET_ITEM_PATH) == null; }
/* 46 */   protected String[] getResponseItemPath() { return RESPONSE_ITEM_PATH; }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException {
/* 49 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 50 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 51 */     OperationContext octxt = getOperationContext(zsc, context);
/* 52 */     ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
/*    */     
/* 54 */     Element target = request.getElement("item");
/* 55 */     String id = target.getAttribute("id", null);
/* 56 */     String folderStr = target.getAttribute("l", null);
/* 57 */     String path = target.getAttribute("path", target.getAttribute("name", null));
/*    */     
/* 59 */     if ((folderStr != null) && (path == null)) {
/* 60 */       throw ServiceException.INVALID_REQUEST("missing required attribute: path", null);
/*    */     }
/*    */     MailItem item;
/* 63 */     if (id != null)
/*    */     {
/* 65 */       item = mbox.getItemById(octxt, new ItemId(id, zsc).getId(), MailItem.Type.UNKNOWN);
/* 66 */     } else if (path != null)
/*    */     {
/* 68 */       int folderId = folderStr == null ? 1 : new ItemId(folderStr, zsc).getId();
/*    */       try {
/* 70 */         item = mbox.getItemByPath(octxt, path, folderId);
/*    */       } catch (MailServiceException.NoSuchItemException nsie) { MailItem item;
/* 72 */         Pair<Folder, String> match = mbox.getFolderByPathLongestMatch(octxt, folderId, path);
/* 73 */         if ((match.getFirst() instanceof Mountpoint)) {
/* 74 */           Mountpoint mpt = (Mountpoint)match.getFirst();
/* 75 */           target.addAttribute("l", mpt.getRemoteId()).addAttribute("path", (String)match.getSecond());
/* 76 */           return proxyRequest(request, context, mpt.getOwnerId());
/*    */         }
/* 78 */         throw nsie;
/*    */       }
/*    */     } else {
/* 81 */       throw ServiceException.INVALID_REQUEST("must specify 'id' or 'path'", null);
/*    */     }
/*    */     MailItem item;
/* 84 */     Element response = zsc.createElement(MailConstants.GET_ITEM_RESPONSE);
/* 85 */     ToXML.encodeItem(response, ifmt, octxt, item, -4194305);
/* 86 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/GetItem.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */